﻿<shared:UserControlBase x:Class="Miris.HumanMilkAnalyser.WPF.CustomizedUserControl.AnalysisResultChartUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:shared="clr-namespace:Miris.HumanMilkAnalyser.WPF.Shared"
             mc:Ignorable="d" 
             d:DesignHeight="90" d:DesignWidth="1000">
    <shared:UserControlBase.Resources>
        <SolidColorBrush x:Key="RangeSeparatorBackground" Color="#c9c9c9" />
        <SolidColorBrush x:Key="LowRangeBackground" Color="#0f1d7a" />
        <SolidColorBrush x:Key="NormalRangeBackground" Color="#a0a0a0" />
        <SolidColorBrush x:Key="HighRangeBackground" Color="#c10e1a" />
    </shared:UserControlBase.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <!-- Item Name -->
            <ColumnDefinition Width="Auto" />
            <!-- Result -->
            <ColumnDefinition Width="Auto" />
            <!-- Chart -->
            <ColumnDefinition Width="1.55*" />
            <!-- Suggestion -->
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Border Width="40" Style="{StaticResource AnalysisReportItemTitleBorder}">
            <TextBlock Padding="10" Width="40" Text="{Binding TestItemTitle}" TextAlignment="Center" Style="{StaticResource AnalysisReportItemTitleTextBlock}" />
        </Border>
        <Border Grid.Column="1" Width="90" BorderThickness="1" BorderBrush="Black">
            <StackPanel VerticalAlignment="Center">
                <TextBlock Text="{Binding TestResult,StringFormat={}{0:F2}}" Style="{StaticResource AnalysisReportItemResultTextBlock}" />
                <TextBlock Text="{Binding TestResultUnit,StringFormat={}({0})}" Style="{StaticResource AnalysisReportItemResultTextBlock}" />
                <TextBlock Text="{Binding TestResultConclusion}" Style="{StaticResource AnalysisReportItemResultTextBlock}" />
                <TextBlock Text="{Binding ExtraInfo}" FontSize="11" Style="{StaticResource AnalysisReportItemResultTextBlock}" />
            </StackPanel>
        </Border>
        <Grid Grid.Column="2">
            <Grid.RowDefinitions>
                <!-- Marker -->
                <RowDefinition Height="Auto" />
                <!-- Chart -->
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition />
                    <ColumnDefinition Width="40" />
                </Grid.ColumnDefinitions>
                <Border BorderBrush="Black" BorderThickness="0,2,2,0">
                    <TextBlock Text="{Binding MinValue}" Style="{StaticResource AnalysisReportResultMakerTextBlock}" />
                </Border>
                <Border Grid.Column="1" BorderBrush="Black" BorderThickness="0,2,2,0">
                    <TextBlock Style="{StaticResource AnalysisReportResultMakerTextBlock}">
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource TestResultChartRangeRulerValueConverter}">
                                <Binding Path="MaxValue" />
                                <Binding Source="1"  />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Border>
                <Border Grid.Column="2" BorderBrush="Black" BorderThickness="0,2,2,0">
                    <TextBlock Style="{StaticResource AnalysisReportResultMakerTextBlock}">
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource TestResultChartRangeRulerValueConverter}">
                                <Binding Path="MaxValue" />
                                <Binding Source="2"  />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Border>
                <Border Grid.Column="3" BorderBrush="Black" BorderThickness="0,2,2,0">
                    <TextBlock Style="{StaticResource AnalysisReportResultMakerTextBlock}">
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource TestResultChartRangeRulerValueConverter}">
                                <Binding Path="MaxValue" />
                                <Binding Source="3"  />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Border>
                <Border Grid.Column="4" BorderBrush="Black" BorderThickness="0,2,2,0">
                    <TextBlock Style="{StaticResource AnalysisReportResultMakerTextBlock}">
                        <TextBlock.Text>
                            <MultiBinding Converter="{StaticResource TestResultChartRangeRulerValueConverter}">
                                <Binding Path="MaxValue" />
                                <Binding Source="4"  />
                            </MultiBinding>
                        </TextBlock.Text>
                    </TextBlock>
                </Border>
                <Border Grid.Column="5">
                    <TextBlock Text="{Binding MaxValue}" Style="{StaticResource AnalysisReportResultMakerTextBlock}" />
                </Border>
            </Grid>
            <Grid Grid.Row="1" Margin="0,0,40,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="2" />
                    <RowDefinition />
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <Grid x:Name="ChartContainer" Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <!-- Low Range -->
                        <ColumnDefinition Width="Auto" />
                        <!-- Range Separator -->
                        <ColumnDefinition Width="2" />
                        <!-- Normal Range -->
                        <ColumnDefinition Width="Auto" />
                        <!-- Range Separator -->
                        <ColumnDefinition Width="2" />
                        <!-- High Range -->
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <!-- Range Value Indicator -->
                        <RowDefinition Height="Auto" />
                        <!-- Main Chart -->
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <!-- Range Start Value Indicator -->
                    <TextBlock HorizontalAlignment="Right" Text="{Binding RangeStartValue,StringFormat={}{0:F2}}" Style="{StaticResource AnalysisReportResultMakerTextBlock}" />
                    <!-- Range Separator -->
                    <Border x:Name="Separator" Grid.Column="1" Background="{StaticResource RangeSeparatorBackground}" />
                    <!-- Range End Value Indicator -->
                    <TextBlock Grid.Column="4" Text="{Binding RangeEndValue,StringFormat={}{0:F2}}" Style="{StaticResource AnalysisReportResultMakerTextBlock}" />
                    <!-- Range Separator -->
                    <Border Grid.Column="3" Background="{StaticResource RangeSeparatorBackground}" />
                    <!-- Low Range -->
                    <Border Grid.Row="1" Background="{StaticResource LowRangeBackground}">
                        <Border.Width>
                            <MultiBinding Converter="{StaticResource TestResultChartItemWidthConverter}">
                                <Binding ElementName="ChartContainer" Path="ActualWidth" />
                                <Binding Path="MaxValue" />
                                <Binding Path="MinValue" />
                                <Binding Path="MinValue" />
                                <Binding Source="0" />
                                <Binding Path="RangeStartValue" />
                            </MultiBinding>
                        </Border.Width>
                    </Border>
                    <!-- Range Separator -->
                    <Border Grid.Row="1" Grid.Column="1" Background="{StaticResource RangeSeparatorBackground}" />
                    <!-- Normal Range -->
                    <Border Grid.Row="1" Grid.Column="2" Background="{StaticResource NormalRangeBackground}">
                        <Border.Width>
                            <MultiBinding Converter="{StaticResource TestResultChartItemWidthConverter}">
                                <Binding ElementName="ChartContainer" Path="ActualWidth" />
                                <Binding Path="MaxValue" />
                                <Binding Path="MinValue" />
                                <Binding Path="RangeStartValue" />
                                <Binding ElementName="Separator" Path="ActualWidth" />
                                <Binding Path="RangeEndValue" />
                            </MultiBinding>
                        </Border.Width>
                    </Border>
                    <!-- Range Separator -->
                    <Border Grid.Row="1" Grid.Column="3" Background="{StaticResource RangeSeparatorBackground}" />
                    <!-- High Range -->
                    <Border Grid.Row="1" Grid.Column="4" Background="{StaticResource HighRangeBackground}" />
                    <!-- Test Result Series -->
                    <Border Grid.Row="1" Grid.ColumnSpan="5" HorizontalAlignment="Left" Height="8" Background="White">
                        <Border.Width>
                            <MultiBinding Converter="{StaticResource TestResultChartItemWidthConverter}">
                                <Binding ElementName="ChartContainer" Path="ActualWidth" />
                                <Binding Path="MaxValue" />
                                <Binding Path="MinValue" />
                                <Binding Path="MinValue" />
                                <Binding Source="0" />
                                <Binding Path="TestResult" />
                            </MultiBinding>
                        </Border.Width>
                    </Border>
                </Grid>
                <!-- Test Item Usage -->
                <TextBlock Grid.Row="2" FontSize="14" Margin="2,0,0,0" Text="{Binding TestItemUsage}" Style="{StaticResource AnalysisReportBlackTextBlock}" />
            </Grid>
        </Grid>
        <!-- Dietary Recommendation -->
        <Border Grid.Column="3" Background="#d4d4d4" Padding="6">
            <TextBlock FontSize="13" Text="{Binding DietaryRecommendation}" HorizontalAlignment="Left" Style="{StaticResource AnalysisReportItemResultTextBlock}" />
        </Border>
    </Grid>
</shared:UserControlBase>